import httpInstance from "@/util/http";

/**
 * 登陆
 * @param account 账号
 * @param password 密码 
 * @returns token
 */
export const loginAPI = ({ account = "", password = "", clientId = '', verifyCode = '' }) => {
    return httpInstance(
        {
            url: '/user/user/login',
            method: 'POST',
            data: {
                username: account,
                password,
                clientId,
                verifyCode
            }
        }
    )
}

/**
 * 获取验证码
 * @param clientId 客户端ID，用于获取验证码和验证验证码
 * @returns 图片流
 */
export const imageValidate = (clientId: string) => {
    return httpInstance({
        url: `/user/verifyCode/image/${clientId}`,
        method: "GET",
        responseType: 'arraybuffer',
    })
}

/**
 * 获取验证码
 * @param clientId 客户端ID，用于获取验证码和验证验证码
 * @returns 图片流
 */
export const phoneValidate = (phoneNo: string) => {
    return httpInstance({
        url: `/user/verifyCode/phone/${phoneNo}`,
        method: "GET",
    })
}


/**
 * 获取验证码
 * @param clientId 客户端ID，用于获取验证码和验证验证码
 * @returns 图片流
 */
export const register = ({
    phoneNo = '',
    account = '',
    password = '',
    verifyCode = ''
}) => {
    return httpInstance({
        url: `/user/registry/phone`,
        method: "POST",
        data: {
            phoneNumber:phoneNo, username: account, password, captcha:verifyCode
        }
    })
}